package com.hn.gege.im.modules.im.controller;

import com.hn.gege.core.common.CommonResult;
import com.hn.gege.im.modules.im.service.ChatWindowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.LinkedList;

@Api(tags = "ChatWindowController", description = "聊天窗口管理")
@RestController
@RequestMapping("/chatWindow")
@Validated
public class ChatWindowController {
    @Autowired
    ChatWindowService chatWindowService;

    @ApiOperation("添加聊天窗口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户账号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "receiver", value = "接收者账号", required = true, dataType = "String", paramType = "query")
    })
    @PostMapping("/add")
    public CommonResult<Boolean> add(@NotBlank String userId, @NotBlank String receiver){
        boolean add = chatWindowService.add(userId, receiver);
        return CommonResult.success(add);
    }

    @ApiOperation("移除聊天窗口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户账号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "receiver", value = "接收者账号", required = true, dataType = "String", paramType = "query")
    })
    @DeleteMapping("/remove")
    public CommonResult<Boolean> remove(@NotBlank String userId, @NotBlank String receiver){
        boolean b = chatWindowService.remove(userId, receiver);
        return CommonResult.success(b);
    }

    @ApiOperation("获取用户所有连天窗口")
    @ApiImplicitParam(name = "userId", value = "用户账号", required = true, dataType = "String", paramType = "query")
    @GetMapping("/listAll")
    public CommonResult<LinkedList<String>> listAll(@NotBlank String userId){
        LinkedList<String> cimSessions = chatWindowService.listAll(userId);
        return CommonResult.success(cimSessions);
    }

}
